var compareString = '';
var graphLetter = 't';
var graphPeriod = '3m';
var graphLetters = {'traffic':'t',
                   'reach':'r',
                   'page':'p',
                   'page_user':'u',
                   'bounce':'b',
                   'time':'s',
                   'search':'q'};
var part_stats = 0;
var part_whois = 0;


function showTab(tab, data, part)
{
	$('#tab_' + tab).addClass('current');
    if (null != data && typeof data != 'undefined') 
	{
		if ($.trim(part) == 2)
			$('#content_' + tab).append(data);
		else
			$('#content_' + tab).html(data);
    }
    $('#content_' + tab).slideDown();
}

$(document).ready(function(){
	$("#selectPeriod").click(function() {
        graphPeriod = this.value;
	    updateGraphic();
	});

    $("#selectPeriod").change(function() {
		graphPeriod = this.value;
		updateGraphic();
	});
});	            


function viewGraphTab(tabName)
{
    $("li[id^=gr_]").removeClass("current");
    $("#gr_" + tabName).addClass("current");
    graphLetter = graphLetters[tabName];
    updateGraphic();
}

function compareTo(tabName)
{
    var compares = '';
    var inputs = $('.compare-to');
    var compareDomain;
    $.each(inputs, function(index, value) {
        compareDomain = $(value).attr('value');
        if ('' != compareDomain) {
            compares += '&u=' + compareDomain;
        }
    });
    compareString = compares;
    updateGraphic();
}
function updateGraphic()
{
    var grQuerySting = 'http://traffic.alexa.com/graph?&w=400&h=220&o=f&c=1&y='
                     + graphLetter
                     + '&b=ffffff&n=666666&r=' + graphPeriod + '&u=' + graphDomain
                     + compareString;
    $('#alexaGraphic').attr({'src':grQuerySting});
}

